sed regex to match ['', 'WR' or 'RN'] + 2-4 digits
Posted
by
Karl
on Stack Overflow
See other posts from Stack Overflow
or by Karl
Published on 2011-01-14T00:35:23Z
Indexed on
2011/01/14
0:53 UTC
Read the original article
Hit count: 420
Hi
I'm trying to do some conditional text processing on Unix and struggling with the syntax. I want to acheive
Find the first 2, 3 or 4 digits in the string
if 2 characters before the found digits are 'WR' (could also be lower case)
Variable = the string we've found (e.g. WR1234)
Type = "work request"
else
if 2 characters before the found digits are 'RN' (could also be lower case)
Variable = the string we've found (e.g. RN1234)
Type = "release note"
else
Variable = "WR" + the string we've found (Prepend 'WR' to the digits)
Type = "Work request"
fi
fi
I'm doing this in a Bash shell on Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Thanks in advance, Karl
© Stack Overflow or respective owner